using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Microblaze.Simulator.Engine;

namespace Weazel.Microblaze.Simulator.Components.Microblaze.Instructions
{
    /// <summary>
    /// Logical Exclusive OR with Immediate
    /// </summary>
    public class Xori : Instruction
    {
        public override int CycleCount
        {
            get { return 1; }
        }

        public Xori()
            : base("xori")
        {
        }

        /// <summary>
        /// The IMM field is extended to 32 bits by concatenating 16 0-bits on the left. 
        /// The contents of register rA are XORed with the extended IMM field; the result 
        /// is placed into register rD.
        /// </summary>    
        public override void Execute(MicroblazeComponent MicroblazeComponent)
        {
            uint ra = MicroblazeComponent.ReadRegister(SourceRegisterA);
            uint imm = (uint)GetImmediateValue(MicroblazeComponent);
            uint rd = ra ^ imm;

            MicroblazeComponent.WriteRegister(DestinationRegister, rd, Address);
        }

        public override string ToString()
        {
            return string.Format("xori r{0}, r{1}, {2}",
              DestinationRegister,
              SourceRegisterA,
              ImmediateValue
            );
        }
    }
}
